package com.dzm.xgb.oss.controller.api;

import com.dzm.common.result.R;
import com.dzm.xgb.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 作者：Dzm
 * 时间：2024-09-04-10:34
 * 功能：
 */

@Api(tags = "oss文件存储管理")
@RestController
@RequestMapping("/api/oss")
public class OssController {

    @Autowired
    private FileService fileService;

    @ApiOperation("上传文件至oss")
    @PostMapping("/import")
    public R uploadFile(@RequestPart("file") MultipartFile file) throws IOException {
        String url = fileService.upload(file);

        return R.ok().data("url", url);
    }

    @ApiOperation("删除oss上的文件")
    @DeleteMapping("/remove")
    public R removeFile(@RequestParam("url") String  fileUrl) {
        fileService.remove(fileUrl);

        return R.ok().message("删除成功！");
    }
}
